package com.ruoyi.web.controller.comlbs;


import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.JSONObjectPro;
import com.ruoyi.common.enums.comlbs.DataDictTypeEnum;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.domain.AlarmType;
import com.ruoyi.system.service.IAlarmTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserAlarmType;
import com.ruoyi.system.service.IUserAlarmTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户告警关系表Controller
 * 
 * @author wp
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/comlbs/userAlarmType")
public class UserAlarmTypeController extends BaseController {
    @Autowired
    private IUserAlarmTypeService userAlarmTypeService;

    /**
     * 查询用户告警关系表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserAlarmType userAlarmType) {
        startPage();
        List<UserAlarmType> list = userAlarmTypeService.selectList(userAlarmType);
        return getDataTable(list);
    }

    /**
     * 获取用户告警关系表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userAlarmTypeService.getById(id));
    }

    @ApiOperation("更新用户报警订阅")
    @Log(title = "用户告警关系表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult edit(@RequestBody Integer[] alarmTypes) {
        userAlarmTypeService.updateAlarmType(alarmTypes);
        return success();
    }

    @ApiOperation("获取用户订阅报警类型")
    @PostMapping(value = "/getUserAlarmTypes")
    public AjaxResult getUserAlarmTypes() {
        List<JSONObjectPro> resultList = userAlarmTypeService.getUserAlarmTypes();
        return success(resultList);
    }
}
